home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / lang / SmallEiffel.lha / SmallEiffel / lib_se / compile.e < prev    next >
Text File  |  1998-12-22  |  5KB  |  171 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class COMPILE -- The command.
  17.  
  18. inherit GLOBALS;
  19.    
  20. creation make
  21.    
  22. feature {NONE}
  23.  
  24.    clean: BOOLEAN;
  25.      -- True if command clean must be called.
  26.    
  27.    make_file: STD_FILE_READ is
  28.       once 
  29.      !!Result.make;
  30.       end;
  31.  
  32.    command: STRING is
  33.       once
  34.      !!Result.make(256);
  35.       end;
  36.    
  37. feature 
  38.    
  39.    make is
  40.       local
  41.      time_out: INTEGER;
  42.      str: STRING;
  43.       do
  44.      if argument_count < 1 then
  45.         system_tools.bad_use_exit("compile");
  46.      end;
  47.      echo.search_for_verbose_flag;
  48.      system_tools.compile_to_c_in(command);
  49.      scan_command_line;
  50.      if run_control.root_class = Void then
  51.         echo.w_put_string("Error : No <Root-Class> in command line.%N");
  52.         die_with_code(exit_failure_code);
  53.      end;
  54.      -- -------------------------------------------- Cleaning :
  55.      -- ---------------------------------------Running script :
  56.      str := system_tools.remove_make_script;
  57.      echo.call_system(command);
  58.          from -- Because of a bug in cygnus/WNT :
  59.             time_out := 2000;
  60.          until
  61.             time_out = 0 or else make_file.is_connected
  62.          loop
  63.             make_file.connect_to(str);
  64.             time_out := time_out - 1;
  65.          end;
  66.      if not make_file.is_connected then
  67.         echo.w_put_string(fz_01);
  68.         echo.w_put_string(str);
  69.         echo.w_put_string("%" not found. %
  70.                 %Error(s) during `compile_to_c'.%N");
  71.         die_with_code(exit_failure_code);
  72.      end;
  73.      echo.put_string("C compiling using %"");
  74.      echo.put_string(str);
  75.      echo.put_string("%" command file.%N");
  76.      from  
  77.         make_file.read_line;
  78.      until
  79.         make_file.last_string.count = 0 
  80.      loop
  81.         command.copy(make_file.last_string);
  82.         echo.call_system(command);
  83.         make_file.read_line;
  84.      end;
  85.      make_file.disconnect;
  86.      -- -------------------------------------------- Cleaning :
  87.      if clean then
  88.         command.clear;
  89.         system_tools.clean_in(command);
  90.         command.extend(' ');
  91.             if echo.verbose then
  92.            command.append(fz_verbose_flag);
  93.            command.extend(' ');
  94.         end;
  95.         command.append(str);
  96.         echo.call_system(command);
  97.      else
  98.         echo.put_string("C code not removed.%N");
  99.      end;
  100.      echo.put_string(fz_02);
  101.       end;
  102.    
  103. feature {NONE}
  104.    
  105.    scan_command_line is
  106.       local
  107.      state, arg: INTEGER;
  108.      a: STRING;
  109.      -- state 0  : nothing done.
  110.      -- state 1  : "-o"/"-cc"/"-cecil" read.
  111.      -- state 2  : Root class name read.
  112.       do
  113.      from  
  114.         arg := 1;
  115.      until
  116.         arg > argument_count
  117.      loop
  118.         a := argument(arg);
  119.         if fz_verbose_flag.is_equal(a) then
  120.            command.extend(' ');
  121.            command.append(a);
  122.         elseif ("-c_code").is_equal(a) then
  123.            echo.w_put_string(
  124.                   "Flag -c_code is now obsolete (this is the default).%N%
  125.                   %See documentation of `compile' (flag -clean).%N");
  126.            clean := false;
  127.         elseif ("-clean").is_equal(a) then
  128.            clean := true;
  129.         else
  130.            command.extend(' ');
  131.            command.append(a);
  132.            inspect 
  133.           state
  134.            when 0 then
  135.           if a.item(1) /= '-' then
  136.              if a.has_suffix(o_suffix) then
  137.              elseif a.has_suffix(c_suffix) then
  138.              elseif a.item(1) = '+' then
  139.              elseif run_control.root_class = Void then
  140.             run_control.compute_root_class(a);
  141.             state := 2;
  142.              else
  143.              end;
  144.           elseif ("-o").is_equal(a) then
  145.              state := 1;
  146.           elseif a.item(1) = '-' and then a.item(2) = 'o' then
  147.           elseif ("-cc").is_equal(a) then
  148.              state := 1;
  149.           elseif ("-cecil").is_equal(a) then
  150.              state := 1;
  151.           else
  152.           end;
  153.            when 1 then
  154.           state := 0;
  155.            when 2 then
  156.           state := 0;
  157.            end;
  158.         end;
  159.         arg := arg + 1;
  160.      end;
  161.       end;
  162.    
  163. feature {NONE}
  164.  
  165.    tmp_file_write: STD_FILE_WRITE is
  166.       once
  167.      !!Result.make;
  168.       end;
  169.  
  170. end -- COMPILE -- The command.
  171.